#include<bits/stdc++.h>
using namespace std;
#define int long long


string rev(string s) {
	reverse(s.begin(), s.end());
	return s;
}


int solution(int n, vector<int> a) {

	// 最大为 2^10-1
	vector<int> nums;

	for (int i = 0; i < 10; i++)	nums.push_back(i);	// 一位数
	for (int i = 1; i < 10; i++)	nums.push_back(stoll(to_string(i) + to_string(i)));
	for (int i = 10; i < 11; i++)	nums.push_back(stoll(to_string(i) + rev(to_string(i))));	// 四位数

	// 三位数
	for (int i = 1; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			nums.push_back(stoll(to_string(i) + to_string(j) + to_string(i)));
		}
	}


	unordered_map<int, int> cnt;
	int ans = 0;

	for (int i : a)	cnt[i]++;

	for (int i : a) {
		for (int j : nums) {
			ans += cnt[i ^ j] > 0 ? cnt[i ^ j] : 0;
		}
		cnt[i]--;
	}
	return ans;
}


signed main() {
//	system("start https://www.lanqiao.cn/problems/3845/learning/");

	int n;
	cin >> n;
	vector<int> a(n);
	for (int &i : a)	cin >> i;

	cout << solution(n, a);

	return 0;
}
